package com.geekstudy.week6;


import com.geekstudy.week6.config.DemoConfig;
import com.geekstudy.week6.config.DemoMultiConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 *
 * 增加一个注解名为 @ConfigSources, 使其能够关联多个 @ConfigSource, 并且在 @ConfigSource 使用 Repeatable,
 * 可以对比参考 Spring 中的 @PropertySources 与 @PropertySource, 并且文字说明 Java 8 @Repeatable 实现原理
 *
 * projects/stage-1/middleware-frameworks/my-configuration/src/main/java/org/geektimes/configuration/microprofile/config/annotation/ConfigSource.java
 *
 *
 *
 * 可选作业, 根据 URL 与 URLStreamHandler 的关系, 扩展一个自定义协议, 可参考
 * sun.net.www.protocol.classpath.Handler
 *
 *
 */

@SpringBootApplication
public class Week6DemoMain {

    static final Logger logger = LoggerFactory.getLogger(Week6DemoMain.class);

    public static void main(String[] args) {

        ConfigurableApplicationContext configurableApplicationContext = SpringApplication.run(Week6DemoMain.class, args);
        logger.info(" beanCount:{} ", configurableApplicationContext.getBeanDefinitionCount());

        // Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException:
        // No qualifying bean of type 'com.geekstudy.week6.config.DemoConfig' available:
        // expected single matching bean but found 2: demoConfig,demo-com.geekstudy.week6.config.DemoConfig
        DemoConfig demoConfig = configurableApplicationContext.getBean("demoConfig", DemoConfig.class);
        logger.info(" demoConfig id:{} name:{} address:{} ", demoConfig.getId(), demoConfig.getName(), demoConfig.getAddress());

        DemoMultiConfig demoMultiConfig = configurableApplicationContext.getBean("demoMultiConfig", DemoMultiConfig.class);
        logger.info(" demoMultiConfig id:{} name:{} url:{} code:{} nick:{} ",
                demoMultiConfig.getId(), demoMultiConfig.getName(), demoMultiConfig.getUrl(), demoMultiConfig.getCode(), demoMultiConfig.getNick());


    }
}
